

#### APPENDIX C6: lagged executive approval


# load, combine data
library(rio)
library(tidyverse)

# estimate models
library(brglm2)

# cluster standard errors
library(lmtest)
library(sandwich)

# generate tables
library(stargazer)




# LOAD DATA
glm_df <- import("glm_data.csv") %>%
  filter(iso3c!="TTO" & iso3c!="GUY" & iso3c!="SUR") %>%
  filter(!is.na(approval) & !is.na(opp1vote) & !is.na(number_protests))



## TABLE C9: all docs
brglm_approval1 <- glm(doc ~ approval_lag1 + opp1vote + number_protests + previous_doc + duck + partyage + polity2 + left_exec + 
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval1_r <- brglm_approval1 %>%
  coeftest(vcovHC(brglm_approval1, type = 'HC0', cluster =  ~ iso3c))


brglm_approval2 <- glm(doc ~ approval_lag2 + opp1vote + number_protests + previous_doc + duck + partyage + polity2 + left_exec + 
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval2_r <- brglm_approval2 %>%
  coeftest(vcovHC(brglm_approval2, type = 'HC0', cluster =  ~ iso3c))


brglm_approval3 <- glm(doc ~ approval_lag3 + opp1vote + number_protests + previous_doc + duck + partyage + polity2 + left_exec + 
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval3_r <- brglm_approval3 %>%
  coeftest(vcovHC(brglm_approval3, type = 'HC0', cluster =  ~ iso3c))


brglm_approval4 <- glm(doc ~ approval_lag4 + opp1vote + number_protests + previous_doc + duck + partyage + polity2 + left_exec + 
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval4_r <- brglm_approval4 %>%
  coeftest(vcovHC(brglm_approval4, type = 'HC0', cluster =  ~ iso3c))


brglm_approval5 <- glm(doc ~ approval_lag5 + opp1vote + number_protests + previous_doc + duck + partyage + polity2 + left_exec + 
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval5_r <- brglm_approval5 %>%
  coeftest(vcovHC(brglm_approval5, type = 'HC0', cluster =  ~ iso3c))

# generate tables
stargazer(brglm_approval1_r,brglm_approval2_r,brglm_approval3_r,brglm_approval4_r,brglm_approval5_r, #type="text",
          omit=c("iso3c","year","quarter"), no.space = T,
          covariate.labels = c("Executive approval (perc), t-1", "Executive approval (perc), t-2", "Executive approval (perc), t-3",
                               "Executive approval (perc), t-4", "Executive approval (perc), t-5",
                               "Opposition vote share (perc)","Number of protests",
                               "Previous document = 1","Lame duck = 1", "Party age",
                               "Democracy","Left executive = 1","Election quarter = 1","Mainstream minister = 1",
                               "Resource rents (perc)","Field discovery = 1","Oil price (USD, log)",
                               "GDP per capita (1,000 USD)","GDP growth (perc)","IMF program = 1", "Crisis = 1"), 
          dep.var.labels = "Any document")

# retrieve n, aic, ll, etc
stargazer(brglm_approval1,brglm_approval2,brglm_approval3,brglm_approval4,brglm_approval5, #type="text",
          omit=c("iso3c","year","quarter"), no.space = T,
          dep.var.labels = "Any document")




## TABLE C10: funds
brglm_approval6 <- glm(fund_doc ~ approval_lag1 + opp1vote + number_protests + previous_fund_doc + duck + partyage + polity2 + left_exec +
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval6_r <- brglm_approval6 %>%
  coeftest(vcovHC(brglm_approval6, type = 'HC0', cluster =  ~ iso3c))


brglm_approval7 <- glm(fund_doc ~ approval_lag2 + opp1vote + number_protests + previous_fund_doc + duck + partyage + polity2 + left_exec +
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval7_r <- brglm_approval7 %>%
  coeftest(vcovHC(brglm_approval7, type = 'HC0', cluster =  ~ iso3c))


brglm_approval8 <- glm(fund_doc ~ approval_lag3 + opp1vote + number_protests + previous_fund_doc + duck + partyage + polity2 + left_exec +
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval8_r <- brglm_approval8 %>%
  coeftest(vcovHC(brglm_approval8, type = 'HC0', cluster =  ~ iso3c))


brglm_approval9 <- glm(fund_doc ~ approval_lag4 + opp1vote + number_protests + previous_fund_doc + duck + partyage + polity2 + left_exec +
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                       family = binomial(link="logit"), 
                       method = "brglmFit",
                       data = glm_df)

brglm_approval9_r <- brglm_approval9 %>%
  coeftest(vcovHC(brglm_approval9, type = 'HC0', cluster =  ~ iso3c))


brglm_approval10 <- glm(fund_doc ~ approval_lag5 + opp1vote + number_protests + previous_fund_doc + duck + partyage + polity2 + left_exec +
                       any_election + minister_is_technocrat_mainstream + 
                       resource_rents_lag + discovery + real_oil_price_log + gdp_pc_constant_lag + gdp_growth_lag + imf_program + crisis +
                       as.factor(iso3c) + as.factor(quarter) + as.factor(year), 
                        family = binomial(link="logit"), 
                        method = "brglmFit",
                        data = glm_df)

brglm_approval10_r <- brglm_approval10 %>%
  coeftest(vcovHC(brglm_approval10, type = 'HC0', cluster =  ~ iso3c))

# generate tables
stargazer(brglm_approval6_r,brglm_approval7_r,brglm_approval8_r,brglm_approval9_r,brglm_approval10_r, #type="text",
          omit=c("iso3c","year","quarter"), no.space = T,
          covariate.labels = c("Executive approval (perc), t-1", "Executive approval (perc), t-2", "Executive approval (perc), t-3",
                               "Executive approval (perc), t-4", "Executive approval (perc), t-5",
                               "Opposition vote share (perc)","Number of protests",
                               "Previous fund document = 1","Lame duck = 1", "Party age",
                               "Democracy","Left executive = 1","Election quarter = 1","Mainstream minister = 1",
                               "Resource rents (perc)","Field discovery = 1","Oil price (USD, log)",
                               "GDP per capita (1,000 USD)","GDP growth (perc)","IMF program = 1", "Crisis = 1"), 
          dep.var.labels = "Fund document")

# retrieve n, aic, ll, etc
stargazer(brglm_approval6,brglm_approval7,brglm_approval8,brglm_approval9,brglm_approval10, #type="text",
          omit=c("iso3c","year","quarter"), no.space = T,
          dep.var.labels = "Fund document")

